﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CFM.API;
using CFM.DTO;
using CFM.Common;
using System.Text.RegularExpressions;

namespace CFM
{
    public partial class frmViewBill : Form
    {
        private BillAPI _apiBill = null;
        public frmViewBill()
        {
            InitializeComponent();
            _apiBill = new BillAPI();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void grvBill_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (grvBill.SelectedRows.Count <= 0)
                return;
            Bill bill = grvBill.SelectedRows[0].DataBoundItem as Bill;
            List<BillDetail> lsBilldetail = new List<BillDetail>();
            lsBilldetail = _apiBill.GetBillDetailByBillId(bill.BillId);
            grvBillDetail.DataSource = lsBilldetail;
            MethodHelper.ClearErrorProvider();
        }

        private void frmViewBill_Load(object sender, EventArgs e)
        {
            grvBill.AutoGenerateColumns = false;
            grvBillDetail.AutoGenerateColumns = false;
            cbxOptionSearch.SelectedIndex = 0;
            grvBill.DataSource = _apiBill.GetAll();
            
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (cbxOptionSearch.Text == "--Tất cả--")
            {
                string keyword = txtKeyWord.Text;
                grvBill.DataSource = _apiBill.GetBillByAll(keyword);
            }
            else if (cbxOptionSearch.Text == "Mã hóa đơn")
            {
                string keyword = txtKeyWord.Text;
                grvBill.DataSource = _apiBill.GetBillByBillId(keyword);
            }
            else if (cbxOptionSearch.Text == "Người lập")
            {
                string keyword = txtKeyWord.Text;
                grvBill.DataSource = _apiBill.GetBillByUerid(keyword);
            }
            else if (cbxOptionSearch.Text == "Ngày lập")
            {
                string keyword = txtKeyWord.Text;
                grvBill.DataSource = _apiBill.GetBillByBillDate(keyword);
            }
        }
    }
}
